using Unity.Collections;
using Unity.Entities;
using UnityEngine;

namespace Game.Core
{
    [UpdateInGroup(typeof(SimulationSystemGroup))]
    public unsafe partial class EventSystem : SystemBase
    {
        EventScheduler<PropertyChangedEvent> PropertyChangedEventScheduler;
        
        protected override void OnCreate()
        {
            Debug.Log("OnCreate");
            PropertyChangedEventScheduler = new EventScheduler<PropertyChangedEvent>(this);
        }

        protected override void OnUpdate()
        {
            Debug.Log("OnUpdate");
            PropertyChangedEventScheduler.Schedule(Dependency);
        }

        public static void Subscribe<TEvent>(EventHandler<TEvent> handler) where TEvent : unmanaged, IComponentData
        {
            EventScheduler<TEvent>.EventHandler += handler;
        }

        public static void Unsubscribe<TEvent>(EventHandler<TEvent> handler) where TEvent : unmanaged, IComponentData
        {
            EventScheduler<TEvent>.EventHandler -= handler;
        }
        
        // public static EventDispatcher<TEvent> CreateEventDispatcher<TEvent>() where TEvent : unmanaged, IComponentData =>
        //     EventScheduler<TEvent>.CreateEventDispatcher();
    }
}